<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../layui/layui.js"></script>
    <script src="../js/jquery-1.8.0.min.js"></script>
    <script src="../js/ajax.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/addPage.css">
</head>

<body>
    <form action="" class="layui-form layui-form-pane">
        <input type="hidden" name="id" id="id" placeholder="请输入标题" autocomplete="off" class="layui-input">
        <div class="layui-form-item">
            <label class="layui-form-label">部门名称</label>
            <div class="layui-input-block">
                <input type="text" name="departmentId" maxlength="30" id="departmentId" required lay-verify="required"
                    placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部门</label>
            <div class="layui-input-block">
                <input type="text" name="departmentName" maxlength="30" id="departmentName" required
                    lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="send" lay-submit lay-filter="AddOrUpdate">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script src="../js/host.js"></script>
    <script>

        $.ajaxSetup({
            headers: {
                "token": localStorage.getItem("token")
            }
        });

        $(function () {
            layui.use(["table", "form"], function () {
                var table = layui.table;
                var form = layui.form;

                form.on("submit(AddOrUpdate)", function (data) {
                    var url = "addDepartment";
                    if ($("#id").val() != null && $("#id").val() != "") {
                        url = "updateDepartment";
                    }

                    new ajax(host + "/" + url, "get", data.field, "json", function (data) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.layer.msg('提交成功', {
                            icon: 1,
                            time: 2000
                        });
                    });

                    $.ajaxSettings.async = true;
                    return false;
                })

            })
        })
    </script>
</body>

</html>